<?php /* SYSTEM $Id: addeditpref.php,v 1.43.4.2 2006/11/05 04:05:31 cyberhorse Exp $ */
##
## add or edit a user preferences
##
$user_id = dPgetParam($_GET, 'user_id', '0');
// Check permissions
if (!$canEdit && $user_id != $AppUI->user_id) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}

// load the preferences
$sql = "
SELECT pref_name, pref_value
FROM user_preferences
WHERE pref_user = $user_id
";
$prefs = db_loadHashList( $sql );

// get the user name
if ($user_id)
	$user = dPgetUsernameFromID($user_id);
else
	$user = "Default";

$titleBlock = new CTitleBlock( 'Edit User Preferences', 'preferences.png' );
$perms =& $AppUI->acl();
if ($perms->checkModule('system', 'edit')) {
	$titleBlock->addButton( "system admin", 'index.php?m=system' );
	$titleBlock->addButton( "system configuration", 'index.php?m=system&a=systemconfig' );
}
$titleBlock->show();
?>
<script language="javascript">
function submitIt(){
	var form = document.changeuser;
	// Collate the checked states of the task log stuff
	var defs = document.getElementById('task_log_email_defaults');
	var mask = 0;
	if (form.tl_assign.checked)
		mask += 1;
	if (form.tl_task.checked)
		mask += 2;
	if (form.tl_proj.checked)
		mask += 4;
	defs.value = mask;
	form.submit();
}
</script>
<form name="changeuser" action="./index.php?m=system" method="post">
	<input type="hidden" name="dosql" value="do_preference_aed" />
	<input type="hidden" name="pref_user" value="<?=$user_id;?>" />
	<input type="hidden" name="del" value="0" />
	<input type="hidden" name="pref_name[TABVIEW]" value="1" />
	<input type="hidden" name="pref_name[TASKASSIGNMAX]" value="100" />

<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
	<td class="tabon"><?=$AppUI->_('User Preferences')?></td>
	<td width="100%">&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="7" cellspacing="0" class="infopanel">
<tr>
	<td>
		<input class="button" type="button" value="<?=$AppUI->_('save');?>" onClick="submitIt()" />
		<input class="button"  type="button" value="<?=$AppUI->_('back');?>" onClick="javascript:history.back(-1);" />
	</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="8" class="subinfopanel">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="3" class="list" width="450px">
	<tr><td colspan="4"><b><?=$AppUI->_('Regional & Language options')?></b></td></tr>
	<tr class="second">
	<td align="right"><?=$AppUI->_('Locale')?>:</td>
	<td>
<?php
	// read the installed languages
	$LANGUAGES = $AppUI->loadLanguages();
	$temp = $AppUI->setWarning( false );
	$langlist = array();
	foreach ($LANGUAGES as $lang => $langinfo)
		$langlist[$lang] = $langinfo[1];
	echo arraySelect($langlist, 'pref_name[LOCALE]', 'class="text" size="1" style="width: 120px"', @$prefs['LOCALE'], true);
	$AppUI->setWarning( $temp );
?>
	</td>
	<td align="right"><?=$AppUI->_('Currency Format')?>:</td>
	<td>
<?php
	$currencies = array();
	$currEx = 1234567.89;

	if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
		$is_win = true;
	else
		$is_win = false;
	foreach (array_keys($LANGUAGES) as $lang) {
		$currencies[$lang] = formatCurrency($currEx, $AppUI->setUserLocale($lang, false));
	}
	echo arraySelect($currencies, 'pref_name[CURRENCYFORM]', 'class="text" size="1" style="width: 120px"', @$prefs['CURRENCYFORM'], false);
?>
	</td>
	</tr>
	<tr class="second">
	<td align="right"><?=$AppUI->_('Date Format')?>:</td>
	<td>
<?php
	// exmample date
	$ex = new CDate();

	$dates = array();
	$f = "%d/%m/%Y"; $dates[$f]	= $ex->format( $f );
	$f = "%d/%b/%Y"; $dates[$f]	= $ex->format( $f );
	$f = "%m/%d/%Y"; $dates[$f]	= $ex->format( $f );
	$f = "%b/%d/%Y"; $dates[$f]	= $ex->format( $f );
	$f = "%d.%m.%Y"; $dates[$f]	= $ex->format( $f );
	$f = "%Y/%b/%d"; $dates[$f] = $ex->format( $f );
	echo arraySelect( $dates, 'pref_name[SHDATEFORMAT]', 'class="text" size="1" style="width: 120px"', @$prefs['SHDATEFORMAT'], false );
?>
	</td>
	<td><?=$AppUI->_('Time Format')?>:</td>
	<td>
<?php
	$times = array();
	$f = "%I:%M %p"; $times[$f]	= $ex->format( $f );
	$f = "%H:%M"; $times[$f]	= $ex->format( $f ).' (24)';
	$f = "%H:%M:%S"; $times[$f]	= $ex->format( $f ).' (24)';
	echo arraySelect( $times, 'pref_name[TIMEFORMAT]', 'class="text" size="1" style="width: 120px"', @$prefs['TIMEFORMAT'], false );
?>
	</td>
	</tr>
	</table>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="3" class="list" width="450px">
	<tr><td colspan="2"><b><?=$AppUI->_('Apperance')?></b></td></tr>
	<tr class="second">
	<td align="right" width="145px"><?=$AppUI->_('User Interface Style')?>:</td>
	<td>
<?php
	$uis = $prefs['UISTYLE'] ? $prefs['UISTYLE'] : 'default';
	$styles = $AppUI->readDirs( 'style' );
	$temp = $AppUI->setWarning( false );
	echo arraySelect( $styles, 'pref_name[UISTYLE]', 'class=text size=1', $uis, true , true);
	$AppUI->setWarning( $temp );
?>
	</td>
	</tr>
	<tr class="second">
	<td align="right" width="145px"><?=$AppUI->_('Default Event Filter')?>:</td>
	<td>
<?php
	require_once $AppUI->getModuleClass('calendar');
	echo arraySelect( $event_filter_list, 'pref_name[EVENTFILTER]', 'class=text size=1', @$prefs['EVENTFILTER'], true);
?>
	</td>
	</tr>
	<tr class="second">
	<td align="right" width="145px"><?=$AppUI->_('Task Notification Method')?>:</td>
	<td>
<?php
	$notify_filter = array(
		0 => 'Do not include task/event owner',
		1 => 'Include task/event owner'
	);

	echo arraySelect( $notify_filter, 'pref_name[MAILALL]', 'class=text size=1', @$prefs['MAILALL'], true);
?>
	</td>
	</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="3" class="list" width="450px">
	<tr><td colspan="4"><b><?=$AppUI->_('Task Log Email')?></b></td></tr>
	<tr class="second">
	<td align="right"><?=$AppUI->_('Subject')?>:</td>
	<td colspan="3">
		<input type='text' name='pref_name[TASKLOGSUBJ]' value='<?php echo @$prefs['TASKLOGSUBJ']; ?>' style="width: 300px">
	</td>
	</tr>
	<tr class="second">
	<td align="right" valign="top" rowspan="2">
		<?=$AppUI->_('Send to')?>:
		<input type="hidden" name="pref_name[TASKLOGEMAIL]" id="task_log_email_defaults"
			value="<?php echo @$prefs['TASKLOGEMAIL']; ?>">
	</td>
<?php
	if (! isset($prefs['TASKLOGEMAIL']))
		$prefs['TASKLOGEMAIL'] = 0;

	$tl_assign = $prefs['TASKLOGEMAIL'] & 1;
	$tl_task = $prefs['TASKLOGEMAIL'] & 2;
	$tl_proj = $prefs['TASKLOGEMAIL'] & 4;
?>
	<td align="center"><label for="tl_assign"><?=$AppUI->_('Assignees')?></label></td>
	<td align="center"><label for="tl_task"><?=$AppUI->_('Task Contacts')?></label></td>
	<td align="center"><label for="tl_proj"><?=$AppUI->_('Project Contacts')?></label></td>
	</tr>
	<tr align="center" class="second">
		<td><input type="checkbox" name="tl_assign" id="tl_assign" <?=$tl_assign ? 'checked="checked"' : ''?>/></td>
		<td><input type="checkbox" name="tl_task" id="tl_task" <?=$tl_task ? 'checked="checked"' : ''?>/></td>
		<td><input type='checkbox' name='tl_proj' id='tl_proj' <?=$tl_proj ? 'checked="checked"' : ''?>/></td>
	</tr>
	<tr class="second">
	<td align="right"><?=$AppUI->_('Recording method')?>:</td>
	<td colspan="3">
	<?php
		$record_method['0'] = $AppUI->_('None');
		$record_method['1'] = $AppUI->_('Apppend to Log');
		echo arraySelect( $record_method, 'pref_name[TASKLOGNOTE]',
				'class="text" size="1" style="width: 305px"', @$prefs['TASKLOGNOTE'], false );
	?>
	</td>
	</tr>
	</table>
</td>
</tr>
</table>
